package com.example.studymybatis.controller;

import com.example.studymybatis.model.dto.UserLoginRequest;
import com.example.studymybatis.model.vo.UserVO;
import com.example.studymybatis.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/user")
@CrossOrigin(origins = {"http://172.20.10.10:8080"}, allowCredentials = "true")
public class UserController {
    @Resource
    private UserService userService;


    @PostMapping("/login")
    public Map<String, Object> login(@RequestBody UserLoginRequest userLoginRequest, HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        if(userLoginRequest == null) {
            map.put("code", "40000");
            map.put("message", "参数不合法！");
            return map;
        }
        UserVO userVO = userService.loginUser(userLoginRequest, request);
        map.put("code", "2000");
        map.put("message", "ok");
        map.put("data", userVO);
        return map;
    }
}
